package org.loneranger.sword.offer05;

/**
 * 请实现一个函数，把字符串 s 中的每个空格替换成"%20"。
 * 输入：s = "We are happy."
 * 输出："We%20are%20happy."
 *
 * @author LoneRanger
 * @version 1.0
 */
public class offer05 {
	public static void main(String[] args) {
		System.out.println(new Solution().replaceSpace("     "));
	}
}

class Solution {
	public String replaceSpace(String s) {
		char[] chars = s.toCharArray();
		s = "";
		for (char aChar : chars) {
			if (Character.isSpaceChar(aChar)) {
				s += "%20";
			} else {
				s += aChar;
			}
		}
		return s;
	}
}
